package cn.sumpu.app.guoguojie.biz.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;

import cn.sumpu.app.guoguojie.biz.IdentifierBiz;
import cn.sumpu.app.guoguojie.biz.RushBiz;
import cn.sumpu.app.guoguojie.dao.RushDao;
import cn.sumpu.app.guoguojie.domain.Rush;
import cn.sumpu.app.guoguojie.domain.RushPhone;
import cn.sumpu.app.guoguojie.domain.RushPlan;
import cn.sumpu.app.guoguojie.domain.RushTime;
import cn.sumpu.app.guoguojie.domain.RushTimePart;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.Common;
import cn.sumpu.app.guoguojie.util.IdGenerator;
import cn.sumpu.app.guoguojie.util.PageModel;

public class RushBizImpl implements RushBiz{
	
	@Resource
	private IdentifierBiz identifierBiz;
	
	private RushDao rushDao;

	public void setRushDao(RushDao rushDao) {
		this.rushDao = rushDao;
	}
	//添加新活动计划
	@Override
	public void insert(Rush rush)throws AppBusinessException {
		rush.setIdentifier(identifierBiz.generateId("rush"));
		rushDao.insert(rush);
	}
	//查询所有的活动计划
	@Override
	public PageModel selectRushList(Integer page) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		int pageSize = 10;
		int startId = (page-1)*pageSize;
		map.put("startId", startId);
		map.put("pageSize", pageSize);
		map.put("orderby", "gmt_created DESC");
		List<Rush> DoingList = rushDao.selectRushList(map);
		int count = rushDao.getRushListCount(map);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		pm.setList(DoingList);
		pm.setPageSize(pageSize);
		pm.setTotalRecord(count);
		pm.setTotalPage((count +pageSize - 1) / pageSize);
		return pm;
	}
	//更新活动计划
	@Override
	public void update(Rush rush)throws AppBusinessException { 
		rushDao.update(rush);
	}
	//更新事件
	@Override
	public void updateRushPlan(RushPlan rushPlan)throws AppBusinessException { 
		rushDao.updateRushPlan(rushPlan);
	}
	
	//删除活动计划
	@Override
	public void delete(String identifier)throws AppBusinessException { 
		rushDao.delete(identifier);
		rushDao.deleteRushTimePartByRushId(identifier);
		rushDao.deleteRushTimeByRushId(identifier);
		rushDao.deleteRushPlanByRushId(identifier); 
		
	}
	//删除事件
	@Override
	public void deleteRushPlan(String identifier)throws AppBusinessException { 
		rushDao.deleteRushPlan(identifier);
	}
	//删除事件时间
	@Override
	public void deleteRushTime(String rushPlanId)throws AppBusinessException { 
		rushDao.deleteRushTime(rushPlanId);
	}
	//删除时间段
	@Override
	public void deleteRushTimePart(String rushPlanId)throws AppBusinessException { 
		rushDao.deleteRushTimePart(rushPlanId);
	}
	
	//查询活动内详情
	@Override
	public List<RushPlan>selectRushPlanByRushId(String identifier)throws AppBusinessException { 
		return rushDao.selectRushPlanList(identifier);
	}
	//查询活动计划
	public Rush select(String identifier)throws AppBusinessException { 
		return rushDao.select(identifier);
	}
	//查询所有中奖用户
	@Override
	public List<RushPhone>selectAllPhone()throws AppBusinessException { 
		return rushDao.selectAllPhone();
	}
	
	//插入秒杀事件
	@Override 
	public void insertRushPlan(RushPlan rushPlan)throws AppBusinessException {
		rushDao.insertRushPlan(rushPlan);
	}
	//插入秒杀时间
	@Override
	public void insertRushTime(RushTime rushTime)throws AppBusinessException {
		rushDao.insertRushTime(rushTime);
		insertRushTimePart(rushTime);
	}
	//查询活动内某一事件的详情
	@Override
	public RushPlan selectPlanByPlanId(String rushPlanId)throws AppBusinessException {
		return rushDao.selectPlanByPlanId(rushPlanId);
	}
	//拆分时间段间隔
	@Override
	public void insertRushTimePart(RushTime rushTime)throws AppBusinessException{
		String  startTimeString =rushTime.getStartTime();
		String  endTimeString =rushTime.getEndTime();
		Integer count =rushTime.getCount();
		SimpleDateFormat secTime = new SimpleDateFormat("HH:mm:ss"); 
	    try { 
			 Date startTimeDate = secTime.parse(startTimeString);
			 Date endTimeDate   = secTime.parse(endTimeString);
			 Calendar calendar = Calendar.getInstance(); 
			    //开始值
			    calendar.setTime(startTimeDate);
			    long startTimeLong =calendar.getTimeInMillis();
			    //结束值
			    calendar.setTime(endTimeDate);
			    long endTimeLong =calendar.getTimeInMillis();
			    //时间段单位间隔
				    	//最小单位<10分钟
				    	int timePartTimeInt=10;
			    		//<10.特殊时间段个数
						    double sTimePartCount=(double)((endTimeLong-startTimeLong)/(1000*60))/timePartTimeInt;
						    int stPartCount = (int)Math.ceil(sTimePartCount);
						    //总数 
						    int partCount=count;
						    //循环
							    for(int m=1;m<=stPartCount;m++){
							    	//平均数 
							    	double rPartCount=partCount/stPartCount;
							    	 int meanCount = (int)Math.ceil(rPartCount);
							    	 if(meanCount==0){
							    		          RushTimePart rushTimePart =new RushTimePart();
												  if(m==stPartCount){
													  int lastCount=partCount;
													  rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
													  rushTimePart.setPartCount(lastCount);
													  rushTimePart.setPartEndTime(Common.getFormatDate(endTimeDate, "HH:mm:ss"));
													  rushTimePart.setRushPlanId(rushTime.getRushPlanId());
													  rushTimePart.setRushTimeId(rushTime.getIdentifier());
													  rushDao.insertRushtPart(rushTimePart);
												  }else{
													  int zeroCount =1;
									    		 		 if(partCount>0){
									    		 			Random no = new Random();	
															zeroCount=no.nextInt(2);
									    		 		 }else{
									    		 			zeroCount =0;
									    		 		 }
													  rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
													  rushTimePart.setPartCount(zeroCount);
													  rushTimePart.setRushPlanId(rushTime.getRushPlanId());
													  rushTimePart.setRushTimeId(rushTime.getIdentifier());
													  rushDao.insertRushtPart(rushTimePart);
													  partCount=partCount-zeroCount;
												  }
												  
							    	 }else{ 
							    		 RushTimePart rushTimePart =new RushTimePart();
											if(m==stPartCount){
												int lastCount=partCount-meanCount*(stPartCount-1);
											     rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
												 rushTimePart.setPartCount(lastCount);
												 rushTimePart.setPartEndTime(Common.getFormatDate(endTimeDate, "HH:mm:ss"));
												 rushTimePart.setRushPlanId(rushTime.getRushPlanId());
												 rushTimePart.setRushTimeId(rushTime.getIdentifier());
												 rushDao.insertRushtPart(rushTimePart);
											}else{
												 rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
												 rushTimePart.setPartCount(meanCount);
												  rushTimePart.setRushPlanId(rushTime.getRushPlanId());
												  rushTimePart.setRushTimeId(rushTime.getIdentifier());
												 rushDao.insertRushtPart(rushTimePart);
											}
							    	 }
							    }
		} catch (ParseException e) {
			e.printStackTrace();
		}
	   
	    
		
	}
	//时间分成若干段
	@Override
	public RushTimePart insterRushPart(Integer partNum,Date startTimeDate,Integer timePartTimeInt)throws AppBusinessException{
		 //拆分成若干的时间段(分)
	    Calendar c = Calendar.getInstance();
	    c.setTime(startTimeDate);
	    //可变开始时间
	    c.add(Calendar.MINUTE, (partNum-1)*timePartTimeInt);
	    Date changeStartTime= c.getTime();
	    String   changeStartTimeString =Common.getFormatDate(changeStartTime, "HH:mm:ss");
	    //可变结束时间
	    c.add(Calendar.MINUTE, timePartTimeInt);
	    Date changeEndTime= c.getTime();
	    String   changeEndTimeString =Common.getFormatDate(changeEndTime, "HH:mm:ss");
	    
	    RushTimePart rushTimePart =new RushTimePart();
	    rushTimePart.setIdentifier(identifierBiz.generateId("rush_time_part"));
	    rushTimePart.setPartStartTime(changeStartTimeString);
	    rushTimePart.setPartEndTime(changeEndTimeString);
		return rushTimePart;
	}
	//寻宝
	@Override
	public synchronized RushPlan selectRushPlanForGrid()throws AppBusinessException {
		List<Rush> rushForGridList =rushDao.selectRushForGrid();
		if(rushForGridList.size()>0){
			try{ 
					List<RushPlan> agreeRushPlSucces=new ArrayList<RushPlan>();
					for(Rush rushIsStart:rushForGridList){
							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
							Date startDate = sdf.parse(rushIsStart.getStartDate());
							Date endDate = sdf.parse(rushIsStart.getEndDate());
							Date nowDate = Calendar.getInstance().getTime();
							Boolean dateIsEnd =nowDate.before(endDate);
							Boolean dateIsStart =nowDate.after(startDate);
							//符合当前年月日规则的活动计划
							if(dateIsEnd==true && dateIsStart==true){
								//查出符合一级当前时间段的规则集合
								List<RushPlan> agreeRushPlanList = rushDao.selectRushPlanListForGrid(rushIsStart.getIdentifier());
								//符合二级规则的事件结合
								for(RushPlan agreeRushPlan:agreeRushPlanList){
									RushPlan rplan = new RushPlan();
									//得到某一事件的当前时间内所有时间结合
									List<RushTimePart> agreeRushTimeList=agreeRushPlan.getRushTimePartListForGrid();
									rplan.setRushTimePartListForGrid(agreeRushTimeList);
									agreeRushPlSucces.add(rplan);
								}
							} 
						} 
					if(agreeRushPlSucces.size()>0 && agreeRushPlSucces!=null){ 
						 
							Random no = new Random();	
							int iplan =agreeRushPlSucces.size();
							int jplan=no.nextInt(iplan);
							RushPlan rushPlanForGrid =agreeRushPlSucces.get(jplan);
							List<RushTimePart>  rushTpartSucces=rushPlanForGrid.getRushTimePartListForGrid();
							if(rushTpartSucces.size()>0 && rushTpartSucces!=null){
								int ipart=rushTpartSucces.size();
								int jpart=no.nextInt(ipart);
								RushTimePart partSuccess =rushTpartSucces.get(jpart);
								if(partSuccess!=null&&partSuccess.getPartCount()>0){
									//秒杀数量-1 
									int reducePartCount =partSuccess.getPartCount()-1;
									partSuccess.setPartCount(reducePartCount);
									rushDao.updateRushTimePart(partSuccess);
									rushDao.updateRushTime(partSuccess.getRushTimeId());
									RushPlan   rushLast = rushDao.selectPlanByPlanId(partSuccess.getRushPlanId());
									return rushLast;
								}
							}
					}
			
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	//定时发布
	@Override
	public void initCountRandomPart()throws AppBusinessException{
		try {
			//System.out.println("timeTimetime");
			rushDao.updateTimeCountE();
			rushDao.deleteAllTimePart();
			List<RushTime> rushTimeList =rushDao.selectAllTime();
			for(RushTime rushTime: rushTimeList){
				insertRushTimePart(rushTime);
			}
		} catch (AppBusinessException e) {
			
		}
	}
	//记录中奖人的信息
	@Override
	public void insertRushPhone(RushPhone rushPhone) throws AppBusinessException{
		rushDao.insertRushPhone(rushPhone);
		
	}
	//判断这个活动是否参加过活动
	@Override
	public Boolean selectPhone(String phoneNum)throws AppBusinessException{
		
		List<RushPhone> rushPhoneList =rushDao.selectPhoneList(phoneNum);
		if(rushPhoneList==null || rushPhoneList.size()==0){
			return true;
		}else{
			return false;
		}
	}
	//根据奖项是否可以/再中奖
	@Override
	public Boolean selectIsWinning(String family,String ip,String rushType,String planId,String phoneNum)throws AppBusinessException{
		
		 if(("02").equals(rushType)){
			 //一日内唯一
			  
			 //家庭号唯一
				 Map<String, Object> mapFamily = new HashMap<String, Object>();
				 mapFamily.put("family", family);
				 mapFamily.put("today", "today");
				 mapFamily.put("rushPlanId", planId);
				 RushPhone rushPhoneWinFamily =rushDao.selectPhoneWin(mapFamily);
			 //ip
				 Map<String, Object> mapIp = new HashMap<String, Object>();
				 mapIp.put("today", "today");
				 mapIp.put("rushIp", ip);
				 mapIp.put("rushPlanId", planId);
				 RushPhone rushPhoneWinIP =rushDao.selectPhoneWin(mapIp);
			 //手机号
				 Map<String, Object> mapPhone = new HashMap<String, Object>();
				 mapPhone.put("today", "today");
				 mapPhone.put("phoneNum", phoneNum);
				 mapPhone.put("rushPlanId", planId);
				 RushPhone rushPhoneWinPhone =rushDao.selectPhoneWin(mapPhone);
				 if(rushPhoneWinIP==null&&rushPhoneWinFamily==null&&rushPhoneWinPhone==null){
					 return true;
				 } 
			    
		 }else if(("03").equals(rushType)){ 
			//活动内唯一 
			 RushPlan rushPlan =rushDao.selectPlanByPlanId(planId);
			 Map<String, Object> mapPlan = new HashMap<String, Object>();
			 mapPlan.put("rushId", rushPlan.getRushId());
			 mapPlan.put("type", rushType);
			 List<RushPlan> planList =rushDao.selectRushPlanList(mapPlan);
			 Boolean boolen =false;
			 for(RushPlan planOne : planList){ 
				 String rushPlanId =planOne.getIdentifier();
					//family
						 Map<String, Object> mapFamily = new HashMap<String, Object>();
						 mapFamily.put("family", family);
						 mapFamily.put("rushPlanId", rushPlanId);
						 RushPhone rushPhoneWinFamily =rushDao.selectPhoneWin(mapFamily);
					//ip
						 Map<String, Object> mapIp = new HashMap<String, Object>();
						 mapIp.put("rushIp", ip);
						 mapIp.put("rushPlanId", rushPlanId);
						 RushPhone rushPhoneWinIP =rushDao.selectPhoneWin(mapIp);
					//手机号
						 Map<String, Object> mapPhone = new HashMap<String, Object>();
						 mapPhone.put("phoneNum", phoneNum);
						 mapPhone.put("rushPlanId", rushPlanId);
						 RushPhone rushPhoneWinPhone =rushDao.selectPhoneWin(mapPhone);
						 if(rushPhoneWinIP==null && rushPhoneWinFamily==null && rushPhoneWinPhone==null){
							 boolen =true;
						 }else{
							 return false;
						 }
			 }
			 return boolen;
		 }
		 return false; 
	}
	
	//查询符合规则的活动计划—事件
	/*@Override
	public synchronized RushPlan selectRushPlanForGrid()throws AppBusinessException {
		//所有的活动计划
		List<Rush> rushForGridList =rushDao.selectRushForGrid();
		if(rushForGridList.size()>0){
			try{
					List<RushPlan> rushPlanIsStartList=new ArrayList<RushPlan>();
					for(Rush rushIsStart:rushForGridList){
							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
							Date startDate = sdf.parse(rushIsStart.getStartDate());
							Date endDate = sdf.parse(rushIsStart.getEndDate());
							Date nowDate = Calendar.getInstance().getTime();
							Boolean dateIsEnd =nowDate.before(endDate);
							Boolean dateIsStart =nowDate.after(startDate);
							//符合当前年月日规则的活动计划
							if(dateIsEnd==true && dateIsStart==true){
								//查出符合当前时间段的规则集合
								List<RushPlan> agreeRushPlanList=selectRushPlanListForGrid(rushIsStart.getIdentifier());
								rushPlanIsStartList.addAll(agreeRushPlanList); 
							} 
						}
					if(rushPlanIsStartList.size()>0){ 
						
							int i =rushPlanIsStartList.size();
							Random no = new Random();	
							int j=no.nextInt(i);
							RushPlan rushPlanForGrid =rushPlanIsStartList.get(j);
							
							List<RushTime>  rushTimeForGrid=rushPlanForGrid.getRushTimeListForGrid();
							//秒杀数量-1
							if(rushTimeForGrid.size()>0){
								int rushCount =rushTimeForGrid.get(0).getCount()-1;
								rushTimeForGrid.get(0).setCount(rushCount);
								rushDao.updateRushTime(rushTimeForGrid.get(0));
							}
							return rushPlanForGrid;
					}
			
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	//查询某活动内的事件集合
	@Override
	public List<RushPlan> selectRushPlanListForGrid(String rushId) throws  AppBusinessException {
		//所有的 
		List<RushPlan> agreeRushPlanList=rushDao.selectRushPlanListForGrid(rushId);
		//符合规则的事件结合
		List<RushPlan> rushPlanListSucces=new ArrayList<RushPlan>();
			try{
				for(RushPlan agreeRushPlan:agreeRushPlanList){
					RushPlan rplan = new RushPlan();
					//符合某一事件的时间结合
					List<RushTime> agreeRushTimeList=agreeRushPlan.getRushTimeListForGrid();
					//存放符合规则的时间集合
					List<RushTime> rushTimeListSucces=new ArrayList<RushTime>();
					
					for(RushTime agreeRushTime: agreeRushTimeList){
						//符合某一事件的某一时间具体值
						String	agreeStartTime = agreeRushTime.getStartTime();
					    String	agreeEndTime   = agreeRushTime.getEndTime();
					    Integer agreeCount     = agreeRushTime.getCustomCount();
					    SimpleDateFormat secTime = new SimpleDateFormat("HH:mm:ss"); 
					    Date startTime = secTime.parse(agreeStartTime);
					    Date endTime   = secTime.parse(agreeEndTime);
					    Calendar calendar = Calendar.getInstance(); 
					    //开始值
					    calendar.setTime(startTime);
					    long startTimeLong =calendar.getTimeInMillis();
					    //结束值
					    calendar.setTime(endTime);
					    long endTimeLong =calendar.getTimeInMillis();
					    //时间段单位
					    double timeMean=(double)((double)(endTimeLong-startTimeLong)/(1000*60))/agreeCount;
					    int timeDanTimeTimeInt = (int)Math.ceil(timeMean); 
				    	//时间段格子
				    	//最小单位>10分钟
				    	if(timeDanTimeTimeInt>=10){
				    		int timDanTimeCount=agreeCount;
				    		for(int x=1;x<=timDanTimeCount;x++){
				    			//格式化开始时间
				    			Boolean rushTimeBoolean =whetherRushTime(startTime,timeDanTimeTimeInt,x);
								if(rushTimeBoolean){
									//查询在当前的格子的剩余总数量
						    		int nowCount =agreeCount-(x-1)*1;
						    		//数据库总数
						    		Integer nowDataCount     = agreeRushTime.getCount();
						    		if(nowDataCount>=nowCount){
						    			//如果前面没被秒完下时间间隔更新数据库
						    			agreeRushTime.setCount(nowCount);
						    			rushDao.updateRushTime(agreeRushTime);
						    			//可以秒杀
						    			rushTimeListSucces.add(agreeRushTime);                            //C.1
						    		}else if(nowDataCount<nowCount){
						    			//秒杀失败(没有库存)
						    		}
								}
				    		 }
				    	}else{
				    		//最小单位<10分钟
				    		timeDanTimeTimeInt=10;
				    		//<10.特殊时间段个数
						    double specialtimeMean=(double)((endTimeLong-startTimeLong)/(1000*60))/timeDanTimeTimeInt;
						    int specialtimeMeanCount = (int)Math.ceil(specialtimeMean);
						    //每个时间段的数量
						    int specialCount = agreeCount/specialtimeMeanCount;
						    //最后一个格子的数量
						     int specialLastCount =agreeCount-((specialtimeMeanCount-1)*specialCount);
						    for(int y=1;y<=specialtimeMeanCount;y++){
						    	//格式化开始时间
						    	Boolean rushTimeBoolean =whetherRushTime(startTime,timeDanTimeTimeInt,y);
								if(rushTimeBoolean){
									if(y==specialtimeMeanCount){
										int nowCount =specialLastCount;
										Integer nowDataCount = agreeRushTime.getCount();
										if(nowDataCount>=nowCount){
											agreeRushTime.setCount(nowCount);
								    		rushDao.updateRushTime(agreeRushTime);
								    		//可以秒杀
								    		rushTimeListSucces.add(agreeRushTime);                          //A.1
										}else{
											//直接秒杀
											rushTimeListSucces.add(agreeRushTime);                          //A.1
										}
									}else{
								    	int nowCount =agreeCount-(y-1)*specialCount;
								    	int nowNextCount =agreeCount-y*specialCount;
								    	Integer nowDataCount = agreeRushTime.getCount();
								    	if(nowDataCount>=nowCount){
							    			//如果前面没被秒完下一时间间隔开始前更新数据库
							    			agreeRushTime.setCount(nowCount);
							    			rushDao.updateRushTime(agreeRushTime);
							    			//可以秒杀(第一位)
							    			rushTimeListSucces.add(agreeRushTime);                           //B.1
							    		}else if(nowCount>nowDataCount && nowDataCount>nowNextCount){
							    			//可以秒杀(第二位以后，已有被秒过奖品但还有剩余)
							    			rushTimeListSucces.add(agreeRushTime);                           //B.1
							    		}else {
							    			//秒杀失败
							    		}
									}
								}
				    		}
				    	}
				}
					rplan.setRushTimeListForGrid(rushTimeListSucces);
					rushPlanListSucces.add(rplan);
			}
				
			}
			catch (ParseException e) {
				e.printStackTrace();
			}
			 
		return rushPlanListSucces;
		
	}
	
	//查询当前时间是否为真
	@Override
	public Boolean whetherRushTime(Date time,Integer timeNum,Integer num) throws  AppBusinessException {
		
			Calendar c = Calendar.getInstance();
			int year = c.get(Calendar.YEAR);
		    int month = c.get(Calendar.MONTH);
		    int day = c.get(Calendar.DATE);
		    c.setTime(time);
		    c.set(Calendar.YEAR, year);
		    c.set(Calendar.MONTH, month);
		    c.set(Calendar.DATE, day);
		    c.add(Calendar.MINUTE, (num-1)*timeNum);
		    //可变开始时间
		    Date changeStartTime= c.getTime();
		    // c.set(Calendar.MINUTE, value)
		    c.add(Calendar.MINUTE, num*timeNum);
		    //可变结束时间
		    Date changeEndTime= c.getTime();
			Date nowTime =new Date();
			Boolean timeIsEnd =nowTime.before(changeEndTime);
			Boolean timeIsStart =nowTime.after(changeStartTime);
			if(timeIsEnd==true && timeIsStart==true){
				return true;
			}else{
				return false;
			}
	}*/
	
	   // double timeMean=(double)((double)(endTimeLong-startTimeLong)/(1000*60))/count;
    //间隔时间(整数)
    // int timePartTimeInt = (int)Math.ceil(timeMean); 
    
	   /* if(timePartTimeInt>=10){
	    		//时间段数量
			     int tPartNum=count;
				 //随机某一格子奖品数量
			     int changeCount =1;
				     for( int m=1;m<=tPartNum;m++){
				    	 if(m==tPartNum){
				    		 RushTimePart rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
				    		 rushTimePart.setPartCount(changeCount);
				    		 rushTimePart.setRushPlanId(rushTime.getRushPlanId());
				    		 rushTimePart.setRushTimeId(rushTime.getIdentifier());
				    		 rushTimePart.setPartEndTime(Common.getFormatDate(endTimeDate, "HH:mm:ss"));
				    		 rushDao.insertRushtPart(rushTimePart);
				    	 }else{
				    		 RushTimePart rushTimePart =insterRushPart(m,startTimeDate,timePartTimeInt);
					    	    rushTimePart.setPartCount(changeCount);
					    	    rushTimePart.setRushPlanId(rushTime.getRushPlanId());
					    	    rushTimePart.setRushTimeId(rushTime.getIdentifier());
					    	    rushDao.insertRushtPart(rushTimePart);
				    	 }
					 }
	    }else{*/
	/*public static void main(String[] args) throws ParseException {
		SimpleDateFormat secTime = new SimpleDateFormat("HH:mm:ss"); 
		//Date nowTime =Calendar.getInstance().getTime();
		
	    Date startTime = secTime.parse("17:01:01");
	    Calendar c = Calendar.getInstance();
	    int year = c.get(Calendar.YEAR);
	    int month = c.get(Calendar.MONTH);
	    int day = c.get(Calendar.DATE);
	    int hour = c.get(Calendar.HOUR_OF_DAY);
	    c.setTime(startTime);
	    c.set(Calendar.YEAR, year);
	    c.set(Calendar.MONTH, month);
	    c.set(Calendar.DATE, day);
	    c.set(Calendar.HOUR_OF_DAY, hour);
	    String date =c.getTime().toString();
	    System.out.println(date);
	}*/
}
